home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9922 < prev    next >
Encoding:
Text File  |  1996-08-05  |  4.7 KB  |  116 lines

  1. Path: news.simi.is!newsadm
  2. From: Bj÷rn Helgason <bjornhp@simi.is>
  3. Newsgroups: comp.lang.misc,comp.lang.c,comp.lang.pl1,comp.lang.apl
  4. Subject: Re: GOTO controversy
  5. Date: Thu, 14 Mar 1996 10:26:30 +0000
  6. Organization: Post and Telecom Iceland, IS-150 Reykjavik, ICELAND
  7. Message-ID: <3147F456.50F0@simi.is>
  8. References: <rcshlds.1.000A6705@mailserv.mta.ca> <4grt4e$8fg@goanna.cs.rmit.EDU.AU> <4hl8mt$4po@newshost.cyberramp.net> <4hlg11$dd7@news1.mnsinc.com> <4hpits$1p1v@b.stat.purdue.edu> <4i0fj8$sd3@tierra.santafe.edu>
  9. NNTP-Posting-Host: simi.is
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (Win95; I)
  14.  
  15. James Giles wrote:
  16. > In 1968, Edsger Dijkstra wrote a letter to the _Communications_
  17. > _of_the_ACM_ titled "Go To Statement Considered Harmful".  This
  18. > paper has since been widely reprinted.  In 1974, Donald Knuth
  19. > wrote a paper for _Computing_Surveys_ titled "Structured
  20. > Programming with GOTO Statements".  This paper has also been
  21. > widely reprinted.  These were not the first nor the only papers
  22. > written on this subject, but to my mind, they should have been
  23. > the last needed.  Anyone who argues this issue should first
  24. > be required to prove he (or she) has read both these papers.
  25. > Anyone who hasn't read these papers should be ignored out
  26. > of hand.
  27. > That being said, I'll go ahead and add my $0.02 to the mix.
  28. > I actually use GOTOs all the time.  Except for the "hello world"
  29. > program, my programs tend to have thousands of GOTO's.  For example,
  30. > an IF without a ELSE clause has one conditional GOTO, with an ELSE
  31. > there's both a conditional and an unconditional branch.  A WHILE
  32. > loop has both conditional and unconditional branches too.
  33. > Now this is both trivially obvious and rather silly.  But it still
  34. > raises the question of why CASE, IF(ELSE), WHILE(FOR, etc.), and
  35. > procedure calls are the only branches anointed as "structured".
  36. > It wasn't always so.  Though these were the constructs mentioned in
  37. > Dijkstra's letter on the subject, there was no suggestion that these
  38. > were the *ONLY* appropriate constructs.
  39.  
  40. < .... many lines deleted .... >
  41.  
  42. > Well, there's a lot more to talk about GOTOs (like exception handling!),
  43. > but this is enough for one article.  The bottom line is that automatic
  44. > rejection of GOTOs for religious reasons loses sight of the real issues
  45. > which led to the controversy and often can lead to unfair disregard for
  46. > techniques which are perfectly sound.  New kinds of GOTOs slowly reach
  47. > into the "structured" pantheon, but only very slowly (and perhaps correctly
  48. > so).  Complete elimination of GOTOs from available languages would stop
  49. > this useful evolution entirely.  In any case, people should not be so quick
  50. > to condemn *all* GOTOs out of hand.  As Dijkstra himself pointed out:
  51. >       Please don't fall into the trap of believing that I am terribly
  52. >       dogmatical about it.  I have a feeling that others are making a
  53. >       religion out of it, as if the conceptual problems of programming
  54. >       could be solved by a single trick, by a simple form of coding
  55. >       discipline!
  56. >                                       - E.W. Dijkstra
  57.  
  58. In the APL world it has often been seen as an inferior style of using
  59. GOTO or even LOOPS at all.
  60.  
  61. In most instances they are not needed. I might add that in ALL cases
  62. you could avoid GOTOs and LOOPs if you really put your mind to it.
  63.  
  64. In the most advanced of languages, J , there were no GOTOs or LOOPs in 
  65. the beginning. They have been introduced in the most recent versions
  66. of J and are now a well appreciated part of J.
  67.  
  68. In the most recent versions of J there are now several Control 
  69. Structures. Not needed according to the purist but I personally
  70. find them easy to use and saves me the hassle of being too clever
  71. all the time.
  72.  
  73. You have:
  74.  
  75. if. ... do. ... end.
  76. if. ... do. ... else. end.
  77. if. ... do. ... elseif. ... do. ... elseif. .. .. .. end.
  78. try. ... catch. ... end.
  79. while. ... do. ... end.
  80. whilst. ... do. ... end.
  81.  
  82. there are even more conventional Control Words:
  83.  
  84. break.
  85. continue.
  86. goto_name.
  87. label_name.
  88. return.
  89.  
  90. Using these kind of structures can simplify the job of initial 
  91. solving a problem of program flow while you are solving a new kind
  92. of challenge.
  93.  
  94. Once you have the system solved I find I can usually go into the
  95. system and remove the control structures.
  96.  
  97. One which is quite handy is the 
  98. try. ... catch. ... end.
  99. But only until you have the system under control then it is actually 
  100. worse. In the catch part you have to be clever to report the error
  101. that occurred. Unless you do not care about the error and always want
  102. to do certain action if the try part does not work and given correct
  103. situation it should.
  104.  
  105.  
  106. -- 
  107. /Gosi
  108. bjornhp@simi.is Bjorn Helgason Spitalastig 4 101 Reykjavik Iceland 354 
  109. 562 5441
  110. http://www.jsoftware.com
  111.